﻿@model HeaderLinksModel
@inject Nop.Core.IWebHelper webHelper

<div class="header-links">
    <ul>
        @await Component.InvokeAsync("Widget", new { widgetZone = PublicWidgetZones.HeaderLinksBefore })
        @if (Model.IsAuthenticated)
        {
            <li><a href="@Url.RouteUrl("CustomerInfo")" class="ico-account">@T("Account.MyAccount")@*@Model.CustomerName*@</a></li>
            <li><a href="@Url.RouteUrl("Logout")" class="ico-logout">@T("Account.Logout")</a></li>
        }
        else
        {
            var returnUrl = Context.Request.Query.TryGetValue("returnUrl", out var url) && !StringValues.IsNullOrEmpty(url) 
                ? url.ToString()
                : webHelper.GetRawUrl(Context.Request);

            <li><a href="@Url.RouteUrl("Register", new { returnUrl })" class="ico-register">@T("Account.Register")</a></li>
            <li><a href="@Url.RouteUrl("Login", new { returnUrl })" class="ico-login">@T("Account.Login")</a></li>
        }
        @if (Model.AllowPrivateMessages)
        {
            <li>
                <a href="@Url.RouteUrl("PrivateMessages", new { tab = "" })" class="ico-inbox">
                    <span class="inbox-label">@T("PrivateMessages.Inbox")</span>
                    <span class="inbox-unread">@Model.UnreadPrivateMessages</span>
                </a>
            </li>
        }
        @if (Model.WishlistEnabled)
        {
            <li>
                <a href="@Url.RouteUrl("Wishlist")" class="ico-wishlist">
                    <span class="wishlist-label">@T("Wishlist")</span>
                    <span class="wishlist-qty">@T("Wishlist.HeaderQuantity", Model.WishlistItems)</span>
                </a>
            </li>
        }
        @if (Model.ShoppingCartEnabled)
        {
            <li id="topcartlink">
                <a href="@Url.RouteUrl("ShoppingCart")" class="ico-cart">
                    <span class="cart-label">@T("ShoppingCart")</span>
                    <span class="cart-qty">@T("ShoppingCart.HeaderQuantity", Model.ShoppingCartItems)</span>
                </a>
            </li>
        }
        @await Component.InvokeAsync("Widget", new { widgetZone = PublicWidgetZones.HeaderLinksAfter })
    </ul>
    @if (Model.AllowPrivateMessages && !string.IsNullOrEmpty(Model.AlertMessage))
    {
        //new private message notification
        <script asp-location="Footer">
            $(document).ready(function () {
                displayPopupNotification('@Html.Raw(JavaScriptEncoder.Default.Encode(Model.AlertMessage))', 'success', false);
            });
        </script>
    }
    @if (Model.ShoppingCartEnabled)
    {
        <script asp-location="Footer">
            $(document).ready(function () {
                $('.header').on('mouseenter', '#topcartlink', function () {
                    $('#flyout-cart').addClass('active');
                });
                $('.header').on('mouseleave', '#topcartlink', function () {
                    $('#flyout-cart').removeClass('active');
                });
                $('.header').on('mouseenter', '#flyout-cart', function () {
                    $('#flyout-cart').addClass('active');
                });
                $('.header').on('mouseleave', '#flyout-cart', function () {
                    $('#flyout-cart').removeClass('active');
                });
            });
        </script>
    }
</div>
